"ui";
var color = "#009688";
ui.layout(
    <drawer id="drawer">
        <vertical>
            <appbar>
                <toolbar id="toolbar" title="示例"/>
            </appbar>
            <button text="按钮" id="an"/>
        </vertical>
        <vertical layout_gravity="left" bg="#ffffff" w="280">
            <img w="280" h="200" scaleType="fitXY" src="http://images.shejidaren.com/wp-content/uploads/2014/10/023746fki.jpg"/>
            <list id="menu">
                <horizontal bg="?selectableItemBackground" w="*">
                    <img w="50" h="50" padding="16" src="{{this.icon}}" tint="{{color}}"/>
                    <text textColor="black" textSize="15sp" text="{{this.title}}" layout_gravity="center"/>
                </horizontal>
            </list>
        </vertical>
    </drawer>
);
//创建选项菜单(右上角)
ui.emitter.on("create_options_menu", menu => {
    menu.add("设置");
    menu.add("关于");
});
//监听选项菜单点击
ui.emitter.on("options_item_selected", (e, item) => {
    switch (item.getTitle()) {
        case "设置":
            toast("还没有设置");
            break;
        case "关于":
            alert("关于", "Auto.js界面模板 v1.0.0");
            break;
    }
    e.consumed = true;
});
activity.setSupportActionBar(ui.toolbar);
//让工具栏左上角可以打开侧拉菜单
ui.toolbar.setupWithDrawer(ui.drawer);

ui.menu.setDataSource([{
        title: "选项一",
        icon: "@drawable/ic_android_black_48dp"
    },
    {
        title: "选项二",
        icon: "@drawable/ic_settings_black_48dp"
    },
    {
        title: "选项三",
        icon: "@drawable/ic_favorite_black_48dp"
    },
    {
        title: "退出",
        icon: "@drawable/ic_exit_to_app_black_48dp"
    }
]);

ui.menu.on("item_click", item => {
    switch (item.title) {
        case "退出":
            ui.finish();
            break;
    }
})

ui.an.on("click",function(){
    toastLog("测试");
});

// // url="https://wwb.lanzout.com/i2khi067qcob"
// // 密码="4oh8"

// // log(蓝奏云解析(url,密码));

// function 蓝奏云解析(url, password) {
//     var rey = http.get(url, {
//         headers: {
//             "Content-Type": "text/html; charset=UTF-8",
//             "User-Agent": "Mozilla/5.0 (Linux; Android 6.0.1; OPPO R9s Plus Build/MMB29M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/55.0.2883.91 Mobile Safari/537.36"
//         }
//     });
//     var a = rey.body.string();
//     var host = url.match(/https:\/\/(.*?)\//)[1];
//     var thisurl = a.match(/var link = \'(.*)\';/)[1];
//     var fileurl = 'https://lanzouw.com/' + thisurl;
//     var res = http.get(fileurl, {
//         headers: {
//             "Content-Type": "text/html; charset=UTF-8",
//             "User-Agent": "Mozilla/5.0 (Linux; Android 6.0.1; OPPO R9s Plus Build/MMB29M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/55.0.2883.91 Mobile Safari/537.36"
//         }
//     });
//     var b = res.body.string();
   
//     if (b.indexOf("输入密码") != -1) {
//         var sign = b.match(/posign = \'(.*?)\'/)[1];
//         var post = 'action=downprocess&sign=' + sign + '&p=' + password;
//         var data = 'https://' + host + '/ajaxm.php';
//         //  var url = "https://wwb.lanzout.com/ajaxm.php";
//         var ret = http.post(data, {
//             "action": "downprocess",
//             "sign": sign,
//             "p": password
//         }, {
//             headers: {
//                 "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
//                 "Referer": "https://lanzouw.com/tp/iInyPo5kb3i",
//                 "User-Agent": "Mozilla/5.0 (Linux; Android 11; PCLM10 Build/RKQ1.200928.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/83.0.4103.106 Mobile Safari/537.36"
//             }
//         });
//         var str = JSON.parse(ret.body.string());
//         arr = [];
//         arr.code = 1;
//         arr.text = '获取成功';
//         arr.data = {}
//         arr.data.name = str.inf;
//         arr.data.url = 获取真实下载直链(str.dom + '/file/' + str.url);
//         arr.data.filename = `\n文件链接：${url}`;
//         return arr;
//     } else {
//         toast("没有密码");
//         //log(b)
//         download = b.match(/pototo = \'(.*?)\';/)[1];
//         fileurl = b.match(/spototo = \'(.*?)\';/)[1];
//         filename = b.match(/<div class="md">(.*?)<span class="mtt">/)[1];
//         // log(download)
//         // log(fileurl)
//         url = download + fileurl;
//         if (url == "") {
//             urlt = b.match(/var cppat = \'(.*?)\';/)[1];
//             urly = b.match(/submit.href =  cppat \+ \'(.*?)\'/)[1];
//             urls = urlt + urly;
//             return 获取真实下载直链(urls);
//         } else {
//             return 获取真实下载直链(url);
//         }
//     }
// }
// function 获取真实下载直链(链接) {
//     conn = new java.net.URL(链接).openConnection();
//     conn.setRequestMethod("GET");
//     conn.setInstanceFollowRedirects(false); //禁止302
//     conn.setRequestProperty("accept-language", "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7"); //设置请求头
//     重定向后链接 = conn.getHeaderField("Location");
//     code = conn.getResponseCode();
//     conn.disconnect();
//     return 重定向后链接;
// }
// //log(蓝奏云解析文件夹(url,passd));
// function 蓝奏云解析文件夹(url, passd) {
//     var rey = http.get(url, {
//         headers: {
//             "Content-Type": "text/html; charset=UTF-8",
//             "User-Agent": "Mozilla/5.0 (Linux; Android 6.0.1; OPPO R9s Plus Build/MMB29M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/55.0.2883.91 Mobile Safari/537.36"
//         }
//     });
//     var a = rey.body.string();
//     var thisurl = a.match(/url : '(.*)',/)[1];
//     var fileurl = 'https://wwb.lanzout.com' + thisurl;
//     var lx = a.match(/'lx':(.*),/)[1];
//     var fid = a.match(/'fid':(.*),/)[1];
//     var uid1 = a.match(/'uid':(.*),/)[1];
//     var pg = a.match(/pgs =(.*);/)[1];
//     var rep1 = a.match(/'rep':(.*),/)[1];
//     var up = a.match(/'up':(.*),/)[1];
//     var ls = a.match(/'ls':(.*),/)[1];
//     let uid = uid1.match(/\d+/)[0];
//     let rep = rep1.match(/\d+/)[0];
//     //	var pgs;var
//     var ss = a.match(/var pgs;\n\tvar(.*);/)[1];
//     var st = a.match(/';\n\tvar (.*);\n\t/)[1];
//     var t = ss.match(/'(.*)'/)[1];
//     var k = st.match(/'(.*)'/)[1]
//     // cd = 文本取中间(a, 'var pgs;', ';');
//     // cd1 = 文本取中间(a, cd + ';', ';');
//     // var t = cd.match(/'(.*)'/)[1];
//     // var k = cd1.match(/'(.*)'/)[1]
//     var ret = http.post(fileurl, {
//         "lx": lx,
//         "fid": fid,
//         "uid": uid,
//         "pg": pg,
//         "rep": rep,
//         "t": t,
//         "k": k,
//         "up": up,
//         "ls": ls,
//         "pwd": passd
//     }, {
//         headers: {
//             "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
//             "User-Agent": "Mozilla/5.0 (Linux; Android 11; PCLM10 Build/RKQ1.200928.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/83.0.4103.106 Mobile Safari/537.36"
//         }
//     });
//     var b = ret.body.json();
//     return b;
//     //文本取中间
//     function 文本取中间(文本内容, 关键字A, 关键字B) {
//         var str = 文本内容;
//         var aPos = str.indexOf(关键字A);
//         var bPos = str.indexOf(关键字B, aPos + 关键字A.length);
//         var retstr = str.substr(aPos + 关键字A.length, 文本内容.length - (aPos + 关键字A.length) - (文本内容.length - bPos));
//         return retstr;
//     }
// }
